<template>
  <div class="titleForm">
    <el-form
      ref="fromRef"
      :rules="{
        title: [{ required: true, message: '标题是必传值', trigger: 'blur' }]
      }"
      label-width="65px"
      :model="info"
    >
      <el-form-item label="标题:" prop="title">
        <el-input v-model="info.title"></el-input>
      </el-form-item>
    </el-form>
    <el-button class="sendbtn" type="success" @click="sendClick">
      发送
    </el-button>
  </div>
</template>

<script lang="ts">
import { reactive, ref, defineComponent } from 'vue'
import { ElForm } from 'element-plus'

export default defineComponent({
  emits: ['sendClick'],
  setup(props, { emit }) {
    const fromRef = ref<InstanceType<typeof ElForm>>()
    const info = reactive<{ title: string }>({
      title: ''
    })
    const sendClick = () => {
      fromRef.value?.validate((valid) => {
        if (valid) {
          emit('sendClick', info.title)
          info.title = ''
        }
      })
    }
    return {
      fromRef,
      info,
      sendClick
    }
  }
})
</script>

<style scoped>
.sendbtn {
  width: 100%;
}
</style>
